import UIKit
import BXModel
{% if not model.ui_is_lib %}
    import SwiftyJSON
    import BXiOSUtils
    import Kingfisher
    import BXForm
{% endif %}

{% for comment in comments %}
    {{ comment }}
{% endfor %}

{% set m = model %}
{% set mname = model.ui_model_name %}
class {{ model.class_name }} : {{ model.superclass }} {{ '' if model.ui_no_bind else ' ,BXBindable' }} {
{% for field in fields %}
    {{ field.declare_stmt }}
{% endfor %}
{{ model.adapter_decl }}

{% if 'TableViewCell' in model.superclass %}
    convenience init() {
    self.init(style: .default, reuseIdentifier: "{{ model.class_name }}Cell")
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    commonInit()
    }
{% else %}
    override init(frame: CGRect) {
    super.init(frame: frame)
    commonInit()
    }
{% endif %}

{% if model.ui_has_bind %}
    var item:{{ mname }}?
    func bind(_ item:{{ mname }}){
    self.item = item
    {% for field in fields %}
        {% if field.can_bind_value %}
            {{ field.bind_value_stmt }}
        {% endif %}
    {% endfor %}
    }
{% endif %}

override func awakeFromNib() {
super.awakeFromNib()
commonInit()
}

{% include 'ios/view/uicommon_init.html' %}


{% if m.is_autolayout %}
    class override func requiresConstraintBasedLayout() -> Bool{
    return true
    }
    override func intrinsicContentSize() -> CGSize {
    return CGSize.zero
    }
{% endif %}

}

